package com.deep.deepenterpise.common.gas;

import com.deep.deepenterpise.common.redis.GasKey;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @author xyz
 * @version 1.0
 * @title DrRedisGasAuthHandler
 * @description
 * @create 2024/4/19 19:18
 */
@Component
public class DrRedisGasAuthHandler implements DrGasAuthKey {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void addKeyWithDelay(GasKey key, String value) {
        stringRedisTemplate.opsForValue().set(key.getKey(), value, key.expireSeconds(), TimeUnit.SECONDS);
    }

    @Override
    public void removeKey(GasKey key) {
        stringRedisTemplate.delete(key.getKey());
    }

    @Override
    public String getKey(GasKey key) {
        return stringRedisTemplate.opsForValue().get(key.getKey());
    }
}
